package com.study.controller;

import com.alibaba.fastjson.JSON;
import com.study.annotation.MyAnnotation1;
import com.study.component1.TestComponent1;
import com.study.dto.UserDto;
import com.study.service.impl.PropagationTest;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author tanglingyu
 * @Date: 2021/04/14/ 17:29
 * @Description
 */
@RestController("/test")
public class TestController1 {

  @Autowired
  private PropagationTest propagationTest;

  @Value("${env}")
  private String env;

  @Autowired
  private TestComponent1 testComponent1;

  //结论环境变量优于配置文件并且会覆盖
  @PostConstruct
  public void test() {
    System.out.println(testComponent1);
    System.out.println(env);
  }

  @RequestMapping("/propagation")
  public void testPropagation() {
    propagationTest.test1();
  }

  @PostMapping("/testList")
  public String testList(@RequestParam Map<String, Object> params) {
    String ss = (String) params.get("order_ids");
    String[] split = ss.split(",");
    List<String> strings = Arrays.asList(split);
    strings.add("sss");
    params.forEach((s, o) -> {
      System.out.println(s);
      System.out.println(o);
    });
    return "tly";
  }

  @PostMapping("/testAspect")
  @MyAnnotation1(name = {"aspect1", "aspect2"})
  public String testAspect(@RequestBody UserDto userDto) {
    return JSON.toJSONString(userDto);
  }
}
